/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 27/08/2012, 12:58:39 PM
 */

package Interfaz;

import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author hC4stillo
 */
public class Principal extends javax.swing.JFrame {

    DefaultTableModel tModel = new DefaultTableModel();
    ArrayList<Object> x= new ArrayList();
    ArrayList<Object> y= new ArrayList();
    /** Creates new form Principal */
    public Principal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTaskPaneGroup1 = new com.l2fprod.common.swing.JTaskPaneGroup();
        jTaskPaneGroup3 = new com.l2fprod.common.swing.JTaskPaneGroup();
        jLinkButton6 = new com.l2fprod.common.swing.JLinkButton();
        jLinkButton7 = new com.l2fprod.common.swing.JLinkButton();
        jLinkButton8 = new com.l2fprod.common.swing.JLinkButton();
        jLinkButton9 = new com.l2fprod.common.swing.JLinkButton();
        jLinkButton10 = new com.l2fprod.common.swing.JLinkButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTaskPaneGroup3.setBackground(new java.awt.Color(255, 204, 51));
        jTaskPaneGroup3.setExpanded(false);
        jTaskPaneGroup3.setTitle("Modelos");
        jTaskPaneGroup3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTaskPaneGroup3MouseClicked(evt);
            }
        });

        jLinkButton6.setText("Lineal");
        jLinkButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jLinkButton6ActionPerformed(evt);
            }
        });
        jTaskPaneGroup3.getContentPane().add(jLinkButton6);

        jLinkButton7.setText("Polinomial");
        jLinkButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jLinkButton7ActionPerformed(evt);
            }
        });
        jTaskPaneGroup3.getContentPane().add(jLinkButton7);

        jLinkButton8.setText("jLinkButton3");
        jTaskPaneGroup3.getContentPane().add(jLinkButton8);

        jLinkButton9.setText("jLinkButton4");
        jTaskPaneGroup3.getContentPane().add(jLinkButton9);

        jLinkButton10.setText("Logaritmico");
        jLinkButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jLinkButton10ActionPerformed(evt);
            }
        });
        jTaskPaneGroup3.getContentPane().add(jLinkButton10);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "X", "Y"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jLabel1.setText("# de datos a ingresar");

        jButton2.setText("Aceptar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jTaskPaneGroup3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 497, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTaskPaneGroup3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/*
 * LinkButton del modelo lineal
 */
    private void jLinkButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jLinkButton6ActionPerformed
        // TODO add your handling code here:
        this.jTaskPaneGroup3.setExpanded(false);
        JPanel lin = new Lineal(this.x,this.y);
        this.jTabbedPane1.add(lin,"Modelo Lineal");
        this.jTabbedPane1.repaint();
    }//GEN-LAST:event_jLinkButton6ActionPerformed
/*
         * Este boton obtiene el numero de datos que vamos a agregar y ajusta la tabla a esa cantidad para que agreguemos datos
         */
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        Object[] id = new Object[2];
        id[0]="X";
        id[1]="Y";
        int n = Integer.parseInt(this.jTextField1.getText());
        this.tModel.setColumnIdentifiers(id);
        this.tModel.setColumnCount(2);
        this.tModel.setRowCount(n);
        this.jTable1.setModel(tModel);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTaskPaneGroup3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTaskPaneGroup3MouseClicked
        // TODO add your handling code here:
        for(int i = 0;i<this.tModel.getRowCount();i++)
        {
        this.y.add(this.tModel.getValueAt(i,1));
        this.x.add(this.tModel.getValueAt(i,0));
        System.out.println(this.x.get(i)+","+this.y.get(i));
        }
    }//GEN-LAST:event_jTaskPaneGroup3MouseClicked

    private void jLinkButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jLinkButton7ActionPerformed
        // TODO add your handling code here:
        //jlinkbutton7-polinomial
        this.jTaskPaneGroup3.setExpanded(false);
        JPanel lin = new Polinomial(this.x,this.y);
        this.jTabbedPane1.add(lin,"Modelo Polinomial");
        this.jTabbedPane1.repaint();
    }//GEN-LAST:event_jLinkButton7ActionPerformed

    private void jLinkButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jLinkButton10ActionPerformed
        // TODO add your handling code here:
        this.jTaskPaneGroup3.setExpanded(false);
        JPanel log = new Logaritmico(this.x,this.y);
        this.jTabbedPane1.add(log,"Modelo Logaritmico");
        this.jTabbedPane1.repaint();
    }//GEN-LAST:event_jLinkButton10ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private com.l2fprod.common.swing.JLinkButton jLinkButton10;
    private com.l2fprod.common.swing.JLinkButton jLinkButton6;
    private com.l2fprod.common.swing.JLinkButton jLinkButton7;
    private com.l2fprod.common.swing.JLinkButton jLinkButton8;
    private com.l2fprod.common.swing.JLinkButton jLinkButton9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private com.l2fprod.common.swing.JTaskPaneGroup jTaskPaneGroup1;
    private com.l2fprod.common.swing.JTaskPaneGroup jTaskPaneGroup3;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}
